﻿using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class RubCardPanel : MonoBehaviour
{
    public GameObject RubCardPrefab;

    private GameObject rubCardGo;

    public RubCard rubCard;

    private Vector2 dragStartPos;

    void Start()
    {

    }

    public void Init()
    {
        //Debug.LogError("----------------------->> RubCardPanel Init() <<-------------------------------------");
        //rubCardGo = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Resources/UI/NewNNCuoPaiGo.prefab");
        //RubCardPrefab = Instantiate(rubCardGo);
        //rubCard = RubCardPrefab.GetComponent<RubCard>();
        rubCard.Init();
    }

    public void SetRubCardPrefab(bool value)
    {
        //RubCardPrefab.SetActive(value);
    }

    public void Closed()
    {
        //rubCard = null;
        //Destroy(RubCardPrefab);
    }

    //重新开始搓牌
    //public void OnPointerClick(PointerEventData eventData)
    //{
    //    rubCard.OnStart();
    //}

    //public void OnDrag(PointerEventData eventData)
    //{
    //    Vector2 dragDistance = dragStartPos - eventData.position;
    //    //if (dragDistance.x > 0)
    //    //{
    //    //    rubCard.SetRatio(dragDistance.x / Screen.width);
    //    //}
    //    
    //    if (startPositionTag == 1)
    //    {
    //        rubCard.SetRatio(dragDistance.y / Screen.height);   // 0 -> -1
    //    }

    //    
    //    if (startPositionTag == 2)
    //    {
    //        rubCard.SetRatio(dragDistance.y / Screen.height);   // 0 -> 1
    //    }

    //    
    //    if (startPositionTag == 3)
    //    {
    //        rubCard.SetRatio(dragDistance.x / Screen.width);    // 0 -> -1
    //    }

    //    
    //    if (startPositionTag == 4)
    //    {
    //        rubCard.SetRatio(dragDistance.x / Screen.width);    // 0 -> 1
    //    }
    //}

    //public void OnBeginDrag(PointerEventData eventData)
    //{
    //    dragStartPos = eventData.position;
    //    UpButtonPostion();
    //}

    //public void OnEndDrag(PointerEventData eventData)
    //{
    //    rubCard.TouchUp();
    //}

    ////
    //int startPositionTag;
    //public void UpButtonPostion()
    //{
    //    float pai_Height = Screen.height / 2;// camera.rect.height / 2;
    //    float pai_Width = Screen.width / 2;//camera.rect.width / 2;
    //    Debug.LogError("pai_Height = " + pai_Height + " pai_Width" + pai_Width);
    //    //Debug.LogError("screenPos.x = " + screenPos.x + " screenPos.y = " + screenPos.y + " screenPos.z = " + screenPos.z);
    //    //Debug.LogError("ViewPos.x = " + ViewPos.x + " ViewPos.y = " + ViewPos.y + " ViewPos.z = " + ViewPos.z);
    //    //
    //    //
    //    //
    //    if (dragStartPos.x / 2 >= pai_Width * 0.2 && dragStartPos.x / 2 <= pai_Width * 0.8 && dragStartPos.y / 2 >= pai_Height * 0.65)//if (startPositoin.x - Screen.width / 2 >= 0 && startPositoin.y - Screen.height / 2 >= 0)
    //    {
    //        
    //        
    //        startPositionTag = 2;
    //    }
    //    else if (dragStartPos.x > Screen.width / 2 && dragStartPos.y / 2 > pai_Height * 0.35 && dragStartPos.y / 2 < pai_Height * 0.65)//if (startPositoin.x - Screen.width / 2 >= 0 && startPositoin.y - Screen.height / 2 < 0)
    //    {
    //        
    //       
    //        startPositionTag = 4;
    //    }
    //    else if (dragStartPos.x / 2 >= pai_Width * 0.2 && dragStartPos.x / 2 <= pai_Width * 0.8 && dragStartPos.y / 2 <= pai_Height * 0.35)//if (startPositoin.x - Screen.width / 2 < 0 && startPositoin.y - Screen.height / 2 >= 0)
    //    {
    //        
    //        
    //        startPositionTag = 1;
    //    }
    //    else if (dragStartPos.x < Screen.width / 2 && dragStartPos.y / 2 > pai_Height * 0.35 && dragStartPos.y / 2 < pai_Height * 0.65)//if (startPositoin.x - Screen.width / 2 < 0 && startPositoin.y - Screen.height / 2 < 0)
    //    {
    //        
    //       
    //        startPositionTag = 3;
    //    }

    //    rubCard.cuoMat.SetFloat("_startPositionTag", startPositionTag);
    //}
}
